﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Game
    {
        
        public bool Gaming(Player player, System NPC)
        {
            int sum = 0;
            int num = 0;
            int nun = 0;
            while (true)
            {
                string playerName;
                playerName = player.Hello();
                Console.WriteLine(player.Name + "   出拳   " + playerName);
                string NPCName;
                NPCName = NPC.Hello();
                Console.WriteLine(NPC.Name + "   出拳   " + NPCName);
                Console.WriteLine(Judge(playerName, NPCName, player.Name, ref num, ref nun));

                sum++;
                while (true)
                {
                    Console.WriteLine("是否开始下一轮？<y/n>");
                    string nextround = Console.ReadLine();
                    if (nextround == "y")
                    {
                        break;
                    }
                    else
                    {
                        return EndGame(player.Name, NPC.Name, sum, num, nun);
                    }
                }
            }
        }
        private bool EndGame(string PlayerName, string NPCName, int sum, int hNum, int uNum)
        {
            Console.WriteLine("===================================");
            Console.WriteLine("对战次数：" + sum);

            Console.WriteLine("姓名\t得分");
            Console.WriteLine(PlayerName + "\t" + hNum);
            Console.WriteLine(NPCName + "\t" + uNum);
            if (hNum > uNum)
            {
                Console.WriteLine($"{PlayerName}赢了，{NPCName}输了");
            }
            else if (hNum < uNum)
            {
                Console.WriteLine($"{PlayerName}赢了，{NPCName}输了");
            }
            else
            {
                Console.WriteLine("平局");
            }
            while (true)
            {
                Console.WriteLine("要开始下一局吗？（y/n）");
                string nextround = Console.ReadLine();
                switch (nextround)
                {
                    case "y":
                        return true;
                    case "n":
                        return false;
                    default:
                        Console.WriteLine("选择错误，请重新输入");
                        continue;
                }
            }
        }
        public string Judge(string A, string B, string name, ref int num, ref int nun)
        {
            string str;
            if ((A == "剪刀" && B == "布") || (A == "石头" && B == "剪刀") || A == "布" && B == "石头")
            {
                num++;
                str = "赢";
            }
            else if (A == B)
            {

                str = "平局";
            }
            else
            {
                nun++;
                str = "输";
            }
            if (str == "赢")
            {
                return $"笨蛋，{name}输了";

            }
            else if (str == "输")
            {
                return $"恭喜，{name}赢了";
            }
            else
            {
                return "平局，真衰！嘿嘿，等着瞧吧！";
            }
        }
    }
}
